//
//  RegisterRequest.m
//  collection
//
//  Created by Jing on 4/5/12.
//  Copyright (c) 2012 Tsinghua University. All rights reserved.
//

#import "RegisterRequest.h"

#pragma mark - [RegisterRequest override methods]

@implementation RegisterRequest

- (void)initParams {
    
    self.descriptionName = @"user.register";
    
    RegisterRequestData* requestData = [[RegisterRequestData alloc] init];
    self.request = requestData;
    [requestData release];
    
    RegisterResponse* response = [[RegisterResponse alloc] init];
    self.response = response;
    [response release];
}

- (NSString*)buildRequestURL {
    
    RegisterRequestData* requestData = (RegisterRequestData*)self.request;
    NSString* requestContent = [NSString stringWithFormat:@"&nick=%@&email=%@&password=%@",
                                requestData.nickname,
                                requestData.email,
                                requestData.password];
    
    return requestContent;
}

- (void)parseResponse:(NSObject *)data {
    
    RegisterResponse* response = (RegisterResponse*)self.response;
    
    NSString* value = nil;
    NSDictionary*dic = (NSDictionary*)data;
    value = [dic objectForKey:@"id"];
    if (value != nil && ![value isEqualToString:@""]) {
        response.userID = value.intValue;
    }
    
    value = [dic objectForKey:@"skey"];
    if (value != nil && ![value isEqualToString:@""]) {
        response.sessionKey = value;
    }
}

@end
